import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:ichinesereader/models/book/BookArguments.dart';
import 'package:ichinesereader/utils/helper.dart';
import 'package:ichinesereader/constants.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/cache.dart';

class SingleBookGridNoBar extends StatefulWidget {
  SingleBookGridNoBar(
      {Key? key,
      required this.bid,
      required this.btitle,
      required this.bcode,
      required this.bimage,
      required this.color,
      required this.bookLevel,
      required this.viewMode})
      : super(key: key);

  //final String title;
  //final List books;
  final String bid;
  final String btitle;
  final String bcode;
  final String bimage;
  final String color;
  final String bookLevel;
  final String viewMode;

  @override
  _SingleBokkGridState createState() => _SingleBokkGridState();
}

class _SingleBokkGridState extends State<SingleBookGridNoBar>
    with SingleTickerProviderStateMixin {
  final box = Hive.box('appconfig');

  @override
  Widget build(BuildContext context) {
    box.put(CacheManagerKey['_viewMode'].toString(), widget.viewMode);
    //Log.debug('widget.btitle---${widget.btitle}');
    return Container(
      alignment: Alignment.center,
      margin: const EdgeInsets.only(top: 12.0),
      child: Padding(
        padding: const EdgeInsets.all(9.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Flexible(
              child: Column(
                children: <Widget>[
                  MouseRegion(
                      cursor: SystemMouseCursors.click,
                      child: GestureDetector(
                        child: Container(
                          child: Image.network(
                            widget.bimage,
                            fit: BoxFit.cover,
                            errorBuilder: (context, error, stackTrace) {
                              return Image.asset(
                                  'assets/images/imagenotavailable.png',
                                  fit: BoxFit.cover);
                            },
                          ),
                          decoration: BoxDecoration(
                            color: Get.theme.primaryColorLight,
                            boxShadow: [
                              BoxShadow(
                                color: hexStringToHexInt(widget.color),
                                spreadRadius: 4,
                                blurRadius: 2,
                                offset: Offset(2, 2),
                              ),
                            ],
                          ),
                        ),
                        onTap: () {
                          if (GetPlatform.isWeb ||
                              GetPlatform.isDesktop ||
                              GetPlatform.isMacOS) {
                            launchInWebViewWithJavaScript(
                                '${Constants.BaseURL}icr/student/book/${widget.bid}');
                          } else {
                            Navigator.pushNamed(context, '/student/book',
                                arguments: BookArguments(
                                    widget.bid,
                                    widget.bcode,
                                    widget.btitle,
                                    null,
                                    NanhaiBookReadingTypes.other,
                                    null));
                          }
                        },
                      )),
                  Padding(
                    padding: const EdgeInsets.only(top: 12.0),
                    child: new GestureDetector(
                      onTap: () {
                        Navigator.pushNamed(context, '/student/book',
                            arguments: BookArguments(
                                widget.bid,
                                widget.bcode,
                                widget.btitle,
                                null,
                                NanhaiBookReadingTypes.other,
                                null));
                        // if(btitle.contains('Pathway'))
                        // {
                        //   Get.defaultDialog(
                        //   title: 'Reminder',
                        //   middleText: 'Please read till the LAST page for the sake of completion/submission',
                        //   onConfirm: () {
                        //     Navigator.pushNamed(context, '/student/book',
                        //         arguments:
                        //             BookArguments(bid, bcode, btitle));

                        //   },
                        //   onCancel: (){},
                        // );

                        // }else
                        // {
                        //   Navigator.pushNamed(context, '/student/book',
                        //         arguments:
                        //             BookArguments(bid, bcode, btitle));

                        // }
                      },
                      child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              ' L${widget.bookLevel} ',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontFamily: 'Montserrat',
                                  backgroundColor:
                                      hexStringToHexInt(widget.color)),
                            ),
                            Flexible(
                              child: Text(
                                ' ${widget.btitle}',
                                maxLines: 2,
                                overflow: TextOverflow.fade,
                                style: Get.textTheme.bodySmall,
                              ),
                            ),
                          ]),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
